<template>
    <!-- 组件的结构 -->
    <div class="demo">
        <h2>学校名称：{{schoolName}}</h2>
        <h2>学校地址：{{address}}</h2>
    </div>
</template>

<script>
    import pubsub from 'pubsub-js'
    export default{
            name:'School-test',
            data(){
            return {
                schoolName:'黑马程序员abc',
                address:'大连'
            }
            },
            mounted(){
                // console.log('school',this.x);
               this.pubId = pubsub.subscribe('hello',(msgName,data)=>{
                    console.log(this);
                    console.log('有人发布了hello消息，hello消息的回调执行了',msgName,data);
                })
            },
            beforeDestroy(){
                pubsub.unsubscribe(this.pubId)
            }
            }
</script>

<style scoped lang="less">
    /* 组件的样式 */
    .demo{
        color: red;
    }
</style>